package com.gopay.scheduler.job;

import com.gopay.common.constants.fund.FundFileSourceConstants;
import com.gopay.common.constants.holiday.HolidayType;
import com.gopay.common.domain.fund.vo.FileBizParam;
import com.gopay.common.exception.GopayException;
import com.gopay.common.util.DateUtils;
import com.gopay.remote.fundcps.service.FileHandlerService;
import com.gopay.remote.cps.holiday.HolidayRemoteService;
import com.gopay.scheduler.GopayBaseJob;
import com.gopay.scheduler.service.fund.FundBaseOperateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 签约文件定时任务
 * @AutoGenFundAgreementInfoJob.java
 * @author baiyunpeng
 * @2016年6月16日 下午6:23:23  www.gopay.com.cn Inc.All rights reserved.
 */
public class FundAgreementFileJob extends GopayBaseJob {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource(name = "fileHandlerService")
    private FileHandlerService fundFileRemoteService;
    @Resource(name = "holidayRemoteService")
    private HolidayRemoteService holidayRemoteService;
    @Autowired
    private FundBaseOperateService operateService;

    @Override
    protected void doJobInternal() {
        try {
            if(!holidayRemoteService.isHoliday(new Date(), HolidayType.FUND_COMPANY)) {
                logger.info("国付宝提供给监管行签约（7文件）生成定时任务开始！============="+ DateUtils.format(new Date()));
                String settleDay = DateUtils.format(new Date(), "yyyyMMdd");
                String res = fundFileRemoteService.superviseAgreementFile(
                        new FileBizParam(settleDay,operateService.queryAllFundCorp(), FundFileSourceConstants.CORN));
                logger.info("国付宝提供给监管行签约（7文件）生成定时任务  :  "+res);
            }
        } catch (Exception e) {
            logger.error("[国付宝提供给监管行签约], to print error message = ["+e.getMessage()+"]",e);
        }
    }
}
